import axios from "@/utils/http"

const token=localStorage.getItem("token");
// console.log(token);




// 获取全部课程
export function getAllClass(){
    // console.log(token);
    
    return axios({
        method:"get",
        url:"/back/class/findAll",


    })
}

// 根据老师id获取课程
// 分页
export function splitPage(page:number,search:any){

  return axios({
    method:"post",
    url:"/back/class/list",
    headers:{
        "Content-Type":"application/json"
    },
    data:{
	    "className": search.className,
        "isCharge": search.isCharge,
        "isCompilation": search.isCompilation,
        "isShelves": search.isShelves,
        "limit": 10,
        "page": page,
        "teacherId": 0
	    
    }
  })
}




// 根据id获取某个课程
export function getOneClass(id:any){
    return axios({
        method:"get",
        url:`/back/class/findDetail/${id}`,

        
    })
}

// 查询课程下的所有视频
export function getVideo(id:any){//class的id
  return axios({
    method:"get",
    url:`/back/video/findByClassId/${id}`,
    // params:{
    //     classId:id
    // }
  })
}

// 上传视频
export function myaddVideo(file:any){
    // return axios.post( "/back/oss/image/video",file,{
    //     headers:{
    //         "Content-Type":"multipart/form-data"
    //     },
    // }
    // )
    return axios.post("/back/oss/image/video",file,{
    headers:{
      "Content-Type":"multipart/form-data"
    }
  })
}

// 添加视频
export function addVi(video:any){
  return axios({
    method:"post",
    url:"/back/video/add",
    headers:{
        "Content-Type":"application/json"
    },
    data:{
	"classId": video.classId,
	"id": 0,
	"serialNumber": video.serialNumber,
	"video": `${video.video}`,
	"videoDuration": video.videoDuration,
	"videoName": video.videoName
}
  })
}




// 查询课程下的某个ship
export function getOneVideo(id:any){//class的id
  return axios({
    method:"get",
    url:`/back/video/findById/${id}`,
    // params:{
    //     id:id
    // }
  })
}

// 修改视频
export function editVi(video:any){
  console.log(video);
  
  return axios({
    method:"put",
    url:"/back/video/upData",
    headers:{
        "Content-Type":"application/json"
    },
    data:{
	"classId": video.classId,
	"id": video.id,
	"serialNumber": video.serialNumber,
	"video": `${video.video}`,
	"videoDuration": video.videoDuration,
	"videoName": video.videoName
}
  })
}

// 删除视频
export function delvideo(id:any){  
  return axios({
    url:`/back/video/deleteById/${id}`,
    method:"DELETE",
    // params:{
    //   id: id
    // }
  })
}

// 添加课程
export function addClass(classs:any){
  return axios({
    method:"post",
    url:"/back/class/add",
    headers:{
        "Content-Type":"application/json"
    },
    data:{
	"className": classs.className,
	"classType": classs.classType,
	"createTime": "",
	"enlistsNum": 0,
	"id": 0,
	"img": classs.img,
	"isCompilation": classs.isCompilation,
	"isShelves": classs.isShelves,
	"price": classs.price,
	"recentNum": 0,
	"teacherId": 0,
	"teachingServices": classs.teachingServices,
	"thematicId": classs.thematicId
}
  })
}
// 编辑课程
export function editClass(classs:any){
  console.log(classs.img);
  console.log(classs);
  
  
  return axios({
    method:"post",
    url:"/back/class/update",
    headers:{
        "Content-Type":"application/json"
    },
    data:{
	"className": classs.className,
	"classType": classs.classType,
	"createTime": "",
	"enlistsNum": 0,
	"id": classs.id,
	"img": classs.img,
	"isCompilation": classs.isCompilation,
	"isShelves": classs.isShelves,
	"price": classs.price,
	"recentNum": 0,

	"teachingServices": classs.teachingServices,
	"thematicId": classs.thematicId
}
  })
}

// 添加考试
export function addclassExam(paper:any){
  return axios({
    url:"/back/paper/addPaper",
    method:"post",
    headers:{
      "Content-Type":"application/json"
    },
    data:{
      "endTime": "",
      "examTime": "",
      "id": 0,
      "name": paper.name,
      "startTime": ""
    }
  })
}

// 上传图片
export function imgUpload(fd:any){
  return axios.post("/back/oss/image/image",fd,{
    headers:{
      "Content-Type":"multipart/form-data"
    }
  })
}


// 删除课程
export function delClass(id:any){
  return axios({
    url:`/back/class/delete/${id}`,
    method:"get"
  })
}





